package tpf.designer.pattern.course10.producer_consumer.sample1;

/**
 * 生产者需要获取篮子这个对象，而且篮子不能是自己创建的
 */
public class Producer implements Runnable {

    SyncStack ss = null;

    public Producer(SyncStack ss) {
        this.ss = ss;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {  //一共要生成10个
            ManTou manTou = new ManTou(i);
            ss.push(manTou);
            System.out.println("生产了：" + manTou);

            try {   //生成一个睡1秒，便于观察
                Thread.sleep((long) (Math.random() * 1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
